<template>
	<el-container>
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="搜索单据编号/产品编码/产品名称" clearable></el-input>
						<el-select v-model="search.pay_type" filterable placeholder="请选择业务状态">
							<el-option label="是" :value="1"/>
							<el-option label="否" :value="2"/>
						</el-select>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
				<div class="left-panel">
					<el-button type="primary" @click="add" v-auth="'production.add'">新增</el-button>
					<el-button type="primary" @click="batch_show" :disabled="selection.length !== 1" v-auth="'production.show'">查看</el-button>
					<el-button type="primary" :disabled="selection.length !== 1" @click="batch_edit" v-auth="'production.edit'">修改</el-button>
					<el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'production.delete'">删除</el-button>
					<el-button type="success" :disabled="selection.length == 0" @click="print" v-auth="'production.print'">打印</el-button>
					<el-button type="warning" :disabled="selection.length == 0" @click="audit" v-auth="'production.audit'">审核</el-button>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="batch_show" @cell-click="cellClick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
					<el-table-column label="单据编号" prop="production_code" align="center">
						<template #default="scope">
							<span style="color: #0099ff;cursor: pointer;">{{ scope.row.production_code }}</span>
						</template>
					</el-table-column>
					<el-table-column label="单据日期" prop="production_date" align="center"></el-table-column>
					<el-table-column label="计划开工日期" prop="plan_start" align="center"></el-table-column>
					<el-table-column label="计划完工日期" prop="plan_end" align="center"></el-table-column>
					<el-table-column label="业务状态" prop="status" align="center">
                        <template #default="scope">
							<el-tag v-if="scope.row.status == 0" type="danger">计划</el-tag>
							<el-tag v-if="scope.row.status == 1 && (scope.row.number != scope.row.ware_number)" type="primary">开工</el-tag>
							<el-tag v-if="scope.row.status == 1 && (scope.row.number == scope.row.ware_number)" type="success">完工</el-tag>
						</template>
                    </el-table-column>
					<el-table-column label="物料编码" prop="product.goods_code" align="center"></el-table-column>
					<el-table-column label="物料名称" prop="product.goods_name" align="center"></el-table-column>
					<el-table-column label="规格型号" prop="product.goods_spec" align="center"></el-table-column>
					<el-table-column label="计划生产数量" prop="number" align="center"></el-table-column>
					<el-table-column label="入库数量" prop="ware_number" align="center"></el-table-column>
					<!-- <el-table-column label="工序进度条" prop="customAddress" align="center"></el-table-column> -->
					<el-table-column label="备注" prop="remark" align="center"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
    <check-status v-if="dialog.check" ref="checkDialog" @success="handleSuccess" @closed="dialog.check = false"></check-status>
</template>

<script>
import CheckStatus from './checkStatus.vue'
export default {
	name: 'user',
	components: {CheckStatus},
	data() {
		return {
			dialog: {
				check: false,
			},
			group: [],
			apiObj: this.$API.production.production.list,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
		}
	},
	methods: {
		/**单元格点击*/
		cellClick(row, column, cell, event) {
			if(column.property == 'production_code') {
				this.$router.push({
					path: '/production/process/processing',
				});
				console.log('11',row, column, cell, event)
			}
		},
		//添加
		add() {
			this.$router.push({
				path: '/production/process/addProcess'
			});
		},
		//编辑
		batch_edit() {
			let form = this.selection[0]
			form.zhuangtai = 'edit'
			this.$router.push({
				path: '/production/process/addProcess',
				query: form
			});
		},
		//查看
		batch_show() {
			let form = this.selection[0]
			form.zhuangtai = 'show'
			this.$router.push({
				path: '/production/process/addProcess',
				query: form
			});
		},
        // 审核
        audit(){
            var ids = [];
			this.selection.forEach((item) => {
				ids.push(item.id)
			})
            this.dialog.check = true
			this.$nextTick(() => {
				this.$refs.checkDialog.open('edit').setData(ids)
			})
        },
        //批量删除
		async batch_del() {
			var delete_ids = [];
			this.selection.forEach((item) => {
				delete_ids.push(item.id)
			})
			this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(() => {
				this.table_del_all(delete_ids)
			}).catch(() => {

			})
		},
        async table_del_all(delete_ids) {
			var reqData = {id: delete_ids}
			var res = await this.$API.production.production.delete.post(reqData);
			if (res.code == 1) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
		selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
